package system

import (
	"context"

	genSysApi "admin_template/bff/admin/hertz_gen/system/sys_api"
	"admin_template/bff/admin/internal/service"

	"github.com/cloudwego/hertz/pkg/app"
)

type ApiRepo interface {
	service.Face
	Default(ctx context.Context, path, method string) bool
	ListByRoleID(ctx context.Context, roleID int64) ([]*genSysApi.Info, error)
}

type ApiService struct {
	*Service
}

func NewApiService(s *Service) *ApiService {
	return &ApiService{s}
}

// Add .
// @router /v1/system/api [POST]
func (s *ApiService) Add(ctx context.Context, c *app.RequestContext) {
	var req genSysApi.AddRequest
	s.AddFunc(s.apiRepo, &req, "apiRepo", "API已存在", ctx, c)
}

// UpdateInfo .
// @router /v1/system/api [PUT]
func (s *ApiService) UpdateInfo(ctx context.Context, c *app.RequestContext) {
	var req genSysApi.UpdateRequest
	s.UpdateInfoFunc(s.apiRepo, &req, "apiRepo", "API已存在", ctx, c)
}

// Del .
// @router /v1/system/api [DELETE]
func (s *ApiService) Del(ctx context.Context, c *app.RequestContext) {
	s.DelFunc(s.apiRepo, "apiRepo", ctx, c)
}

// UpdateState .
// @router /v1/system/api/state [PUT]
func (s *ApiService) UpdateState(ctx context.Context, c *app.RequestContext) {
	s.UpdateStateFunc(s.apiRepo, "apiRepo", ctx, c)
}

// List .
// @router /v1/system/api [GET]
func (s *ApiService) List(ctx context.Context, c *app.RequestContext) {
	var req genSysApi.ListRequest
	s.ListFunc(s.apiRepo, &req, "apiRepo", ctx, c)
}

// All .
// @router /v1/system/api/all [GET]
func (s *ApiService) All(ctx context.Context, c *app.RequestContext) {
	var req genSysApi.AllRequest
	s.AllFunc(s.apiRepo, &req, "apiRepo", ctx, c)
}
